import RequestProcess from "./RequestProcess";
import OperateArgs from "../operator/OperateArgs";
import OperatorDecorator from "../operator/OperatorDecorator";
import BuildFriendOperation from "../operator/BuildFriendOperation";
import { RC } from "../config/RC";
import CheckUserIdExistOperator from "../operator/CheckUserIdExistOperator";


class BuildFriendRequestProcess extends RequestProcess {

    public args_generate(): void {
        this.args = new OperateArgs();
        this.args.setProperty("userId", this.req.body.userId);
        this.args.setProperty("friendId", this.req.body.friendId);
    }

    public operator_plan_generate(): void {
        const check_userId_Exist = new CheckUserIdExistOperator(this.args);
        const build_friend_operation = new BuildFriendOperation(this.args);

        this.operator_plan = new OperatorDecorator(check_userId_Exist,build_friend_operation);
    }

    public writeResult(rc: RC): Object {
        switch (rc) {
            case RC.SUCCESS:
                return {
                    code: "0000",
                    msg: "添加好友成功"
                }
            case RC.FRIENDCREATE_FAILURE:
                return {
                    code: "1009",
                    msg: "添加好友失败"
                }
            case RC.INTERNAL_ERROR:
                return {
                    code: "1003",
                    msg: "服务器内部错误"
                }
            default:
                return {
                    code: "2000",
                    msg: "未知错误"
                }
        }
    }
}

export default BuildFriendRequestProcess;